Grammar model for structured search queries

ABSTRACT

In one embodiment, a method includes accessing a social graph that includes a plurality of nodes and edges, receiving an unstructured text query, identifying nodes and edges that correspond to n-grams of the text query, accessing a context-free grammar model, identifying grammars having query tokens that correspond to the identified nodes and edges, determining a score for each identified grammar, and then generating structured queries based on the identified grammars based on strings generated by the grammars.

PRIORITY

This application is a continuation under 35 U.S.C. §120 of U.S. patentapplication Ser. No. 13/674,695, filed 12 Nov. 2012.

TECHNICAL FIELD

This disclosure generally relates to social graphs and performingsearches for objects within a social-networking environment.

BACKGROUND

A social-networking system, which may include a social-networkingwebsite, may enable its users (such as persons or organizations) tointeract with it and with each other through it. The social-networkingsystem may, with input from a user, create and store in thesocial-networking system a user profile associated with the user. Theuser profile may include demographic information, communication-channelinformation, and information on personal interests of the user. Thesocial-networking system may also, with input from a user, create andstore a record of relationships of the user with other users of thesocial-networking system, as well as provide services (e.g. wall posts,photo-sharing, event organization, messaging, games, or advertisements)to facilitate social interaction between or among users.

The social-networking system may transmit over one or more networkscontent or messages related to its services to a mobile or othercomputing device of a user. A user may also install softwareapplications on a mobile or other computing device of the user foraccessing a user profile of the user and other data within thesocial-networking system. The social-networking system may generate apersonalized set of content objects to display to a user, such as anewsfeed of aggregated stories of other users connected to the user.

Social-graph analysis views social relationships in terms of networktheory consisting of nodes and edges. Nodes represent the individualactors within the networks, and edges represent the relationshipsbetween the actors. The resulting graph-based structures are often verycomplex. There can be many types of nodes and many types of edges forconnecting nodes. In its simplest form, a social graph is a map of allof the relevant edges between all the nodes being studied.

SUMMARY OF PARTICULAR EMBODIMENTS

In particular embodiments, in response to a text query received from auser, a social-networking system may generate structured queriescomprising query tokens that correspond to identified social-graphelements. By providing suggested structured queries in response to auser's text query, the social-networking system may provide a powerfulway for users of an online social network to search for elementsrepresented in a social graph based on their social-graph attributes andtheir relation to various social-graph elements.

In particular embodiments, the social-networking system may receive asubstantially unstructured text query from a user. In response, thesocial-networking system may access a social graph and then parse thetext query to identify social-graph elements that corresponded ton-grams from the text query. The social-networking system may identifythese corresponding social-graph elements by determining a probabilityfor each n-gram that it corresponds to a particular social-graphelement. The social-networking system may then access a grammar model,such as a context-free grammar model. The identified social-graphelements may be used as terminal tokens (“query tokens”) in the grammarsof the grammar model, and each grammar may then be scored. Grammars witha score greater than a threshold score may be used to generatestructured queries that include query tokens referencing the identifiedsocial-graph elements. The structured queries may then be transmittedand displayed to the user, where the user can then select an appropriatequery to search for the desired content.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 illustrates an example network environment associated with asocial-networking system.

FIG. 2 illustrates an example social graph.

FIG. 3 illustrates an example webpage of an online social network.

FIGS. 4A-4B illustrate example queries of the social network.

FIG. 5 illustrates an example method for using a context-free grammarmodel to generate structured search queries.

FIG. 6 illustrates an example computer system.

DESCRIPTION OF EXAMPLE EMBODIMENTS

System Overview

FIG. 1 illustrates an example network environment 100 associated with asocial-networking system. Network environment 100 includes a clientsystem 130, a social-networking system 160, and a third-party system 170connected to each other by a network 110. Although FIG. 1 illustrates aparticular arrangement of client system 130, social-networking system160, third-party system 170, and network 110, this disclosurecontemplates any suitable arrangement of client system 130,social-networking system 160, third-party system 170, and network 110.As an example and not by way of limitation, two or more of client system130, social-networking system 160, and third-party system 170 may beconnected to each other directly, bypassing network 110. As anotherexample, two or more of client system 130, social-networking system 160,and third-party system 170 may be physically or logically co-locatedwith each other in whole or in part. Moreover, although FIG. 1illustrates a particular number of client systems 130, social-networkingsystems 160, third-party systems 170, and networks 110, this disclosurecontemplates any suitable number of client systems 130,social-networking systems 160, third-party systems 170, and networks110. As an example and not by way of limitation, network environment 100may include multiple client system 130, social-networking systems 160,third-party systems 170, and networks 110.

This disclosure contemplates any suitable network 110. As an example andnot by way of limitation, one or more portions of network 110 mayinclude an ad hoc network, an intranet, an extranet, a virtual privatenetwork (VPN), a local area network (LAN), a wireless LAN (WLAN), a widearea network (WAN), a wireless WAN (WWAN), a metropolitan area network(MAN), a portion of the Internet, a portion of the Public SwitchedTelephone Network (PSTN), a cellular telephone network, or a combinationof two or more of these. Network 110 may include one or more networks110.

Links 150 may connect client system 130, social-networking system 160,and third-party system 170 to communication network 110 or to eachother. This disclosure contemplates any suitable links 150. Inparticular embodiments, one or more links 150 include one or morewireline (such as for example Digital Subscriber Line (DSL) or Data OverCable Service Interface Specification (DOCSIS)), wireless (such as forexample Wi-Fi or Worldwide Interoperability for Microwave Access(WiMAX)), or optical (such as for example Synchronous Optical Network(SONET) or Synchronous Digital Hierarchy (SDH)) links. In particularembodiments, one or more links 150 each include an ad hoc network, anintranet, an extranet, a VPN, a LAN, a WLAN, a WAN, a WWAN, a MAN, aportion of the Internet, a portion of the PSTN, a cellulartechnology-based network, a satellite communications technology-basednetwork, another link 150, or a combination of two or more such links150. Links 150 need not necessarily be the same throughout networkenvironment 100. One or more first links 150 may differ in one or morerespects from one or more second links 150.

In particular embodiments, client system 130 may be an electronic deviceincluding hardware, software, or embedded logic components or acombination of two or more such components and capable of carrying outthe appropriate functionalities implemented or supported by clientsystem 130. As an example and not by way of limitation, a client system130 may include a computer system such as a desktop computer, notebookor laptop computer, netbook, a tablet computer, e-book reader, GPSdevice, camera, personal digital assistant (PDA), handheld electronicdevice, cellular telephone, smartphone, other suitable electronicdevice, or any suitable combination thereof. This disclosurecontemplates any suitable client systems 130. A client system 130 mayenable a network user at client system 130 to access network 110. Aclient system 130 may enable its user to communicate with other users atother client systems 130.

In particular embodiments, client system 130 may include a web browser132, such as MICROSOFT INTERNET EXPLORER, GOOGLE CHROME or MOZILLAFIREFOX, and may have one or more add-ons, plug-ins, or otherextensions, such as TOOLBAR or YAHOO TOOLBAR. A user at client system130 may enter a Uniform Resource Locator (URL) or other addressdirecting the web browser 132 to a particular server (such as server162, or a server associated with a third-party system 170), and the webbrowser 132 may generate a Hyper Text Transfer Protocol (HTTP) requestand communicate the HTTP request to server. The server may accept theHTTP request and communicate to client system 130 one or more Hyper TextMarkup Language (HTML) files responsive to the HTTP request. Clientsystem 130 may render a webpage based on the HTML files from the serverfor presentation to the user. This disclosure contemplates any suitablewebpage files. As an example and not by way of limitation, webpages mayrender from HTML files, Extensible Hyper Text Markup Language (XHTML)files, or Extensible Markup Language (XML) files, according toparticular needs. Such pages may also execute scripts such as, forexample and without limitation, those written in JAVASCRIPT, JAVA,MICROSOFT SILVERLIGHT, combinations of markup language and scripts suchas AJAX (Asynchronous JAVASCRIPT and XML), and the like. Herein,reference to a webpage encompasses one or more corresponding webpagefiles (which a browser may use to render the webpage) and vice versa,where appropriate.

In particular embodiments, social-networking system 160 may be anetwork-addressable computing system that can host an online socialnetwork. Social-networking system 160 may generate, store, receive, andtransmit social-networking data, such as, for example, user-profiledata, concept-profile data, social-graph information, or other suitabledata related to the online social network. Social-networking system 160may be accessed by the other components of network environment 100either directly or via network 110. In particular embodiments,social-networking system 160 may include one or more servers 162. Eachserver 162 may be a unitary server or a distributed server spanningmultiple computers or multiple datacenters. Servers 162 may be ofvarious types, such as, for example and without limitation, web server,news server, mail server, message server, advertising server, fileserver, application server, exchange server, database server, proxyserver, another server suitable for performing functions or processesdescribed herein, or any combination thereof. In particular embodiments,each server 162 may include hardware, software, or embedded logiccomponents or a combination of two or more such components for carryingout the appropriate functionalities implemented or supported by server162. In particular embodiments, social-networking system 164 may includeone or more data stores 164. Data stores 164 may be used to storevarious types of information. In particular embodiments, the informationstored in data stores 164 may be organized according to specific datastructures. In particular embodiments, each data store 164 may be arelational database. Particular embodiments may provide interfaces thatenable a client system 130, a social-networking system 160, or athird-party system 170 to manage, retrieve, modify, add, or delete, theinformation stored in data store 164.

In particular embodiments, social-networking system 160 may store one ormore social graphs in one or more data stores 164. In particularembodiments, a social graph may include multiple nodes—which may includemultiple user nodes (each corresponding to a particular user) ormultiple concept nodes (each corresponding to a particular concept)—andmultiple edges connecting the nodes. Social-networking system 160 mayprovide users of the online social network the ability to communicateand interact with other users. In particular embodiments, users may jointhe online social network via social-networking system 160 and then addconnections (i.e., relationships) to a number of other users ofsocial-networking system 160 whom they want to be connected to. Herein,the term “friend” may refer to any other user of social-networkingsystem 160 with whom a user has formed a connection, association, orrelationship via social-networking system 160.

In particular embodiments, social-networking system 160 may provideusers with the ability to take actions on various types of items orobjects, supported by social-networking system 160. As an example andnot by way of limitation, the items and objects may include groups orsocial networks to which users of social-networking system 160 maybelong, events or calendar entries in which a user might be interested,computer-based applications that a user may use, transactions that allowusers to buy or sell items via the service, interactions withadvertisements that a user may perform, or other suitable items orobjects. A user may interact with anything that is capable of beingrepresented in social-networking system 160 or by an external system ofthird-party system 170, which is separate from social-networking system160 and coupled to social-networking system 160 via a network 110.

In particular embodiments, social-networking system 160 may be capableof linking a variety of entities. As an example and not by way oflimitation, social-networking system 160 may enable users to interactwith each other as well as receive content from third-party systems 170or other entities, or to allow users to interact with these entitiesthrough an application programming interfaces (API) or othercommunication channels.

In particular embodiments, a third-party system 170 may include one ormore types of servers, one or more data stores, one or more interfaces,including but not limited to APIs, one or more web services, one or morecontent sources, one or more networks, or any other suitable components,e.g., that servers may communicate with. A third-party system 170 may beoperated by a different entity from an entity operatingsocial-networking system 160. In particular embodiments, however,social-networking system 160 and third-party systems 170 may operate inconjunction with each other to provide social-networking services tousers of social-networking system 160 or third-party systems 170. Inthis sense, social-networking system 160 may provide a platform, orbackbone, which other systems, such as third-party systems 170, may useto provide social-networking services and functionality to users acrossthe Internet.

In particular embodiments, a third-party system 170 may include athird-party content object provider. A third-party content objectprovider may include one or more sources of content objects, which maybe communicated to a client system 130. As an example and not by way oflimitation, content objects may include information regarding things oractivities of interest to the user, such as, for example, movie showtimes, movie reviews, restaurant reviews, restaurant menus, productinformation and reviews, or other suitable information. As anotherexample and not by way of limitation, content objects may includeincentive content objects, such as coupons, discount tickets, giftcertificates, or other suitable incentive objects.

In particular embodiments, social-networking system 160 also includesuser-generated content objects, which may enhance a user's interactionswith social-networking system 160. User-generated content may includeanything a user can add, upload, send, or “post” to social-networkingsystem 160. As an example and not by way of limitation, a usercommunicates posts to social-networking system 160 from a client system130. Posts may include data such as status updates or other textualdata, location information, photos, videos, links, music or othersimilar data or media. Content may also be added to social-networkingsystem 160 by a third-party through a “communication channel,” such as anewsfeed or stream.

In particular embodiments, social-networking system 160 may include avariety of servers, sub-systems, programs, modules, logs, and datastores. In particular embodiments, social-networking system 160 mayinclude one or more of the following: a web server, action logger,API-request server, relevance-and-ranking engine, content-objectclassifier, notification controller, action log,third-party-content-object-exposure log, inference module,authorization/privacy server, search module, ad-targeting module,user-interface module, user-profile store, connection store, third-partycontent store, or location store. Social-networking system 160 may alsoinclude suitable components such as network interfaces, securitymechanisms, load balancers, failover servers,management-and-network-operations consoles, other suitable components,or any suitable combination thereof. In particular embodiments,social-networking system 160 may include one or more user-profile storesfor storing user profiles. A user profile may include, for example,biographic information, demographic information, behavioral information,social information, or other types of descriptive information, such aswork experience, educational history, hobbies or preferences, interests,affinities, or location. Interest information may include interestsrelated to one or more categories. Categories may be general orspecific. As an example and not by way of limitation, if a user “likes”an article about a brand of shoes the category may be the brand, or thegeneral category of “shoes” or “clothing.” A connection store may beused for storing connection information about users. The connectioninformation may indicate users who have similar or common workexperience, group memberships, hobbies, educational history, or are inany way related or share common attributes. The connection informationmay also include user-defined connections between different users andcontent (both internal and external). A web server may be used forlinking social-networking system 160 to one or more client systems 130or one or more third-party system 170 via network 110. The web servermay include a mail server or other messaging functionality for receivingand routing messages between social-networking system 160 and one ormore client systems 130. An API-request server may allow a third-partysystem 170 to access information from social-networking system 160 bycalling one or more APIs. An action logger may be used to receivecommunications from a web server about a user's actions on or offsocial-networking system 160. In conjunction with the action log, athird-party-content-object log may be maintained of user exposures tothird-party-content objects. A notification controller may provideinformation regarding content objects to a client system 130.Information may be pushed to a client system 130 as notifications, orinformation may be pulled from client system 130 responsive to a requestreceived from client system 130. Authorization servers may be used toenforce one or more privacy settings of the users of social-networkingsystem 160. A privacy setting of a user determines how particularinformation associated with a user can be shared. The authorizationserver may allow users to opt in or opt out of having their actionslogged by social-networking system 160 or shared with other systems(e.g., third-party system 170), such as, for example, by settingappropriate privacy settings. Third-party-content-object stores may beused to store content objects received from third parties, such as athird-party system 170. Location stores may be used for storing locationinformation received from client systems 130 associated with users.Ad-pricing modules may combine social information, the current time,location information, or other suitable information to provide relevantadvertisements, in the form of notifications, to a user.

Social Graphs

FIG. 2 illustrates example social graph 200. In particular embodiments,social-networking system 160 may store one or more social graphs 200 inone or more data stores. In particular embodiments, social graph 200 mayinclude multiple nodes—which may include multiple user nodes 202 ormultiple concept nodes 204—and multiple edges 206 connecting the nodes.Example social graph 200 illustrated in FIG. 2 is shown, for didacticpurposes, in a two-dimensional visual map representation. In particularembodiments, a social-networking system 160, client system 130, orthird-party system 170 may access social graph 200 and relatedsocial-graph information for suitable applications. The nodes and edgesof social graph 200 may be stored as data objects, for example, in adata store (such as a social-graph database). Such a data store mayinclude one or more searchable or queryable indexes of nodes or edges ofsocial graph 200.

In particular embodiments, a user node 202 may correspond to a user ofsocial-networking system 160. As an example and not by way oflimitation, a user may be an individual (human user), an entity (e.g.,an enterprise, business, or third-party application), or a group (e.g.,of individuals or entities) that interacts or communicates with or oversocial-networking system 160. In particular embodiments, when a userregisters for an account with social-networking system 160,social-networking system 160 may create a user node 202 corresponding tothe user, and store the user node 202 in one or more data stores. Usersand user nodes 202 described herein may, where appropriate, refer toregistered users and user nodes 202 associated with registered users. Inaddition or as an alternative, users and user nodes 202 described hereinmay, where appropriate, refer to users that have not registered withsocial-networking system 160. In particular embodiments, a user node 202may be associated with information provided by a user or informationgathered by various systems, including social-networking system 160. Asan example and not by way of limitation, a user may provide his or hername, profile picture, contact information, birth date, sex, maritalstatus, family status, employment, education background, preferences,interests, or other demographic information. In particular embodiments,a user node 202 may be associated with one or more data objectscorresponding to information associated with a user. In particularembodiments, a user node 202 may correspond to one or more webpages.

In particular embodiments, a concept node 204 may correspond to aconcept. As an example and not by way of limitation, a concept maycorrespond to a place (such as, for example, a movie theater,restaurant, landmark, or city); a website (such as, for example, awebsite associated with social-network system 160 or a third-partywebsite associated with a web-application server); an entity (such as,for example, a person, business, group, sports team, or celebrity); aresource (such as, for example, an audio file, video file, digitalphoto, text file, structured document, or application) which may belocated within social-networking system 160 or on an external server,such as a web-application server; real or intellectual property (suchas, for example, a sculpture, painting, movie, game, song, idea,photograph, or written work); a game; an activity; an idea or theory;another suitable concept; or two or more such concepts. A concept node204 may be associated with information of a concept provided by a useror information gathered by various systems, including social-networkingsystem 160. As an example and not by way of limitation, information of aconcept may include a name or a title; one or more images (e.g., animage of the cover page of a book); a location (e.g., an address or ageographical location); a website (which may be associated with a URL);contact information (e.g., a phone number or an email address); othersuitable concept information; or any suitable combination of suchinformation. In particular embodiments, a concept node 204 may beassociated with one or more data objects corresponding to informationassociated with concept node 204. In particular embodiments, a conceptnode 204 may correspond to one or more webpages.

In particular embodiments, a node in social graph 200 may represent orbe represented by a webpage (which may be referred to as a “profilepage”). Profile pages may be hosted by or accessible tosocial-networking system 160. Profile pages may also be hosted onthird-party websites associated with a third-party server 170. As anexample and not by way of limitation, a profile page corresponding to aparticular external webpage may be the particular external webpage andthe profile page may correspond to a particular concept node 204.Profile pages may be viewable by all or a selected subset of otherusers. As an example and not by way of limitation, a user node 202 mayhave a corresponding user-profile page in which the corresponding usermay add content, make declarations, or otherwise express himself orherself. As another example and not by way of limitation, a concept node204 may have a corresponding concept-profile page in which one or moreusers may add content, make declarations, or express themselves,particularly in relation to the concept corresponding to concept node204.

In particular embodiments, a concept node 204 may represent athird-party webpage or resource hosted by a third-party system 170. Thethird-party webpage or resource may include, among other elements,content, a selectable or other icon, or other inter-actable object(which may be implemented, for example, in JavaScript, AJAX, or PHPcodes) representing an action or activity. As an example and not by wayof limitation, a third-party webpage may include a selectable icon suchas “like,” “check in,” “eat,” “recommend,” or another suitable action oractivity. A user viewing the third-party webpage may perform an actionby selecting one of the icons (e.g., “eat”), causing a client system 130to transmit to social-networking system 160 a message indicating theuser's action. In response to the message, social-networking system 160may create an edge (e.g., an “eat” edge) between a user node 202corresponding to the user and a concept node 204 corresponding to thethird-party webpage or resource and store edge 206 in one or more datastores.

In particular embodiments, a pair of nodes in social graph 200 may beconnected to each other by one or more edges 206. An edge 206 connectinga pair of nodes may represent a relationship between the pair of nodes.In particular embodiments, an edge 206 may include or represent one ormore data objects or attributes corresponding to the relationshipbetween a pair of nodes. As an example and not by way of limitation, afirst user may indicate that a second user is a “friend” of the firstuser. In response to this indication, social-networking system 160 maytransmit a “friend request” to the second user. If the second userconfirms the “friend request,” social-networking system 160 may createan edge 206 connecting the first user's user node 202 to the seconduser's user node 202 in social graph 200 and store edge 206 associal-graph information in one or more of data stores 24. In theexample of FIG. 2, social graph 200 includes an edge 206 indicating afriend relation between user nodes 202 of user “A” and user “B” and anedge indicating a friend relation between user nodes 202 of user “C” anduser “B.” Although this disclosure describes or illustrates particularedges 206 with particular attributes connecting particular user nodes202, this disclosure contemplates any suitable edges 206 with anysuitable attributes connecting user nodes 202. As an example and not byway of limitation, an edge 206 may represent a friendship, familyrelationship, business or employment relationship, fan relationship,follower relationship, visitor relationship, subscriber relationship,superior/subordinate relationship, reciprocal relationship,non-reciprocal relationship, another suitable type of relationship, ortwo or more such relationships. Moreover, although this disclosuregenerally describes nodes as being connected, this disclosure alsodescribes users or concepts as being connected. Herein, references tousers or concepts being connected may, where appropriate, refer to thenodes corresponding to those users or concepts being connected in socialgraph 200 by one or more edges 206.

In particular embodiments, an edge 206 between a user node 202 and aconcept node 204 may represent a particular action or activity performedby a user associated with user node 202 toward a concept associated witha concept node 204. As an example and not by way of limitation, asillustrated in FIG. 2, a user may “like,” “attended,” “played,”“listened,” “cooked,” “worked at,” or “watched” a concept, each of whichmay correspond to a edge type or subtype. A concept-profile pagecorresponding to a concept node 204 may include, for example, aselectable “check in” icon (such as, for example, a clickable “check in”icon) or a selectable “add to favorites” icon. Similarly, after a userclicks these icons, social-networking system 160 may create a “favorite”edge or a “check in” edge in response to a user's action correspondingto a respective action. As another example and not by way of limitation,a user (user “C”) may listen to a particular song (“Imagine”) using aparticular application (SPOTIFY, which is an online music application).In this case, social-networking system 160 may create a “listened” edge206 and a “used” edge (as illustrated in FIG. 2) between user nodes 202corresponding to the user and concept nodes 204 corresponding to thesong and application to indicate that the user listened to the song andused the application. Moreover, social-networking system 160 may createa “played” edge 206 (as illustrated in FIG. 2) between concept nodes 204corresponding to the song and the application to indicate that theparticular song was played by the particular application. In this case,“played” edge 206 corresponds to an action performed by an externalapplication (SPOTIFY) on an external audio file (the song “Imagine”).Although this disclosure describes particular edges 206 with particularattributes connecting user nodes 202 and concept nodes 204, thisdisclosure contemplates any suitable edges 206 with any suitableattributes connecting user nodes 202 and concept nodes 204. Moreover,although this disclosure describes edges between a user node 202 and aconcept node 204 representing a single relationship, this disclosurecontemplates edges between a user node 202 and a concept node 204representing one or more relationships. As an example and not by way oflimitation, an edge 206 may represent both that a user likes and hasused at a particular concept. Alternatively, another edge 206 mayrepresent each type of relationship (or multiples of a singlerelationship) between a user node 202 and a concept node 204 (asillustrated in FIG. 2 between user node 202 for user “E” and conceptnode 204 for “SPOTIFY”).

In particular embodiments, social-networking system 160 may create anedge 206 between a user node 202 and a concept node 204 in social graph200. As an example and not by way of limitation, a user viewing aconcept-profile page (such as, for example, by using a web browser or aspecial-purpose application hosted by the user's client system 130) mayindicate that he or she likes the concept represented by the conceptnode 204 by clicking or selecting a “Like” icon, which may cause theuser's client system 130 to transmit to social-networking system 160 amessage indicating the user's liking of the concept associated with theconcept-profile page. In response to the message, social-networkingsystem 160 may create an edge 206 between user node 202 associated withthe user and concept node 204, as illustrated by “like” edge 206 betweenthe user and concept node 204. In particular embodiments,social-networking system 160 may store an edge 206 in one or more datastores. In particular embodiments, an edge 206 may be automaticallyformed by social-networking system 160 in response to a particular useraction. As an example and not by way of limitation, if a first useruploads a picture, watches a movie, or listens to a song, an edge 206may be formed between user node 202 corresponding to the first user andconcept nodes 204 corresponding to those concepts. Although thisdisclosure describes forming particular edges 206 in particular manners,this disclosure contemplates forming any suitable edges 206 in anysuitable manner.

Typeahead Processes

In particular embodiments, one or more client-side and/or backend(server-side) processes implement and utilize a “typeahead” feature toautomatically attempt to match concepts corresponding to respectiveexisting user nodes 202 or concept nodes 204 to information currentlybeing entered by a user in an input form rendered in conjunction with arequested webpage, such as a user-profile page, which may be hosted oraccessible in, by the social-networking system 160. In particularembodiments, as a user is entering text to make a declaration, thetypeahead feature attempts to match the string of textual charactersbeing entered in the declaration to strings of characters (e.g., names)corresponding to existing concepts (or users) and corresponding concept(or user) nodes in the social graph 200. In particular embodiments, whena match is found, the typeahead feature may automatically populate theform with a reference to the node (such as, for example, the node name,node ID, or another suitable reference or identifier) of the existingnode.

In particular embodiments, as a user types or otherwise enters text intoa form used to add content or make declarations in various sections ofthe user's profile page or other page, the typeahead process may work inconjunction with one or more frontend (client-side) and/or backend(server-side) typeahead processes (hereinafter referred to simply as“typeahead process”) executing at (or within) the social-networkingsystem 160 (e.g., within servers 162), to interactively and virtuallyinstantaneously (as appearing to the user) attempt to auto-populate theform with a term or terms corresponding to names of existingsocial-graph entities, or terms associated with existing social-graphentities, determined to be the most relevant or best match to thecharacters of text entered by the user as the user enters the charactersof text. Utilizing the social-graph information in a social-graphdatabase or information extracted and indexed from the social-graphdatabase, including information associated with nodes and edges, thetypeahead processes, in conjunction with the information from thesocial-graph database, as well as potentially in conjunction withvarious others processes, applications, or databases located within orexecuting within social-networking system 160, are able to predict auser's intended declaration with a high degree of precision. However,social-networking system 160 also provides user's with the freedom toenter any declaration they wish enabling users to express themselvesfreely.

In particular embodiments, as a user enters text characters into a formbox or other field, the typeahead processes may attempt to identifyexisting social-graph elements (e.g., user nodes 202, concept nodes 204,or edges 206) that match the string of characters entered in the user'sdeclaration as the user is entering the characters. In particularembodiments, as the user enters characters into a form box, thetypeahead process may read the string of entered textual characters. Aseach keystroke is made, the frontend-typeahead process may transmit theentered character string as a request (or call) to the backend-typeaheadprocess executing within social-networking system 160. In particularembodiments, the typeahead processes may communicate via AJAX(Asynchronous JavaScript and XML) or other suitable techniques, andparticularly, asynchronous techniques. In one particular embodiment, therequest is, or comprises, an XMLHTTPRequest (XHR) enabling quick anddynamic sending and fetching of results. In particular embodiments, thetypeahead process also transmits before, after, or with the request asection identifier (section ID) that identifies the particular sectionof the particular page in which the user is making the declaration. Inparticular embodiments, a user ID parameter may also be sent, but thismay be unnecessary in some embodiments, as the user is already “known”based on he or she logging into social-networking system 160.

In particular embodiments, the typeahead process may use one or morematching algorithms to attempt to identify matching social-graphelements. In particular embodiments, when a match or matches are found,the typeahead process may transmit a response (which may utilize AJAX orother suitable techniques) to the user's client system 130 that mayinclude, for example, the names (name strings) of the matchingsocial-graph elements as well as, potentially, other metadata associatedwith the matching social-graph elements. As an example and not by way oflimitation, if a user entering the characters “pok” into a query field,the typeahead process may display a drop-down menu that displays namesof matching existing profile pages and respective user nodes 202 orconcept nodes 204 (e.g., a profile page named or devoted to “poker”),which the user can then click on or otherwise select thereby confirmingthe desire to declare the matched user or concept name corresponding tothe selected node. As another example and not by way of limitation, uponclicking “poker,” the typeahead process may auto-populate, or causes theweb browser 132 to auto-populate, the query field with the declaration“poker”. In particular embodiments, the typeahead process may simplyauto-populate the field with the name or other identifier of thetop-ranked match rather than display a drop-down menu. The user may thenconfirm the auto-populated declaration simply by keying “enter” on hisor her keyboard or by clicking on the auto-populated declaration.

More information on typeahead processes may be found in U.S. patentapplication Ser. No. 12/763,162, filed 19 Apr. 2010, and U.S. patentapplication Ser. No. 13/556,072, filed 23 Jul. 2012, which areincorporated by reference.

Structured Search Queries

FIG. 3 illustrates an example webpage of an online social network. Inparticular embodiments, a user may submit a query to the social-networksystem 160 by inputting a text query into query field 350. A user of anonline social network may search for information relating to a specificsubject matter (e.g., users, concepts, external content or resource) byproviding a short phrase describing the subject matter, often referredto as a “search query,” to a search engine. The query may be anunstructured text query and may comprise one or more text strings or oneor more n-grams. In general, a user may input any character string intoquery field 350 to search for content on the social-networking system160 that matches the text query. The social-networking system 160 maythen search a data store 164 (or, more particularly, a social-graphdatabase) to identify content matching the query. The search engine mayconduct a search based on the query phrase using various searchalgorithms and generate search results that identify resources orcontent (e.g., user-profile pages, content-profile pages, or externalresources) that are most likely to be related to the search query. Toconduct a search, a user may input or transmit a search query to thesearch engine. In response, the search engine may identify one or moreresources that are likely to be related to the search query, which maycollectively be referred to as a “search result” identified for thesearch query. The identified content may include, for example,social-graph entities (i.e., user nodes 202, concept nodes 204, edges206), profile pages, external webpages, or any combination thereof. Thesocial-networking system 160 may then generate a search results webpagewith search results corresponding to the identified content. The searchresults may be presented to the user, often in the form of a list oflinks on search-results webpage, each link being associated with adifferent webpage that contains some of the identified resources orcontent. In particular embodiments, each link in the search results maybe in the form of a Uniform Resource Locator (URL) that specifies wherethe corresponding webpage is located and the mechanism for retrievingit. The social-networking system 160 may then transmit the searchresults webpage to the user's web browser 132 on the user's clientsystem 130. The user may then click on the URL links or otherwise selectthe content from the search results webpage to access the content fromthe social-networking system 160 or from an external system, asappropriate. The resources may be ranked and presented to the useraccording to their relative degrees of relevance to the search query.The search results may also be ranked and presented to the useraccording to their relative degree of relevance to the user. In otherwords, the search results may be personalized for the querying userbased on, for example, social-graph information, user information,search or browsing history of the user, or other suitable informationrelated to the user. In particular embodiments, ranking of the resourcesmay be determined by a ranking algorithm implemented by the searchengine. As an example and not by way of limitation, resources that aremore relevant to the search query or to the user may be ranked higherthan the resources that are less relevant to the search query or theuser. In particular embodiments, the search engine may limit its searchto resources and content on the online social network. However, inparticular embodiments, the search engine may also search for resourcesor contents on other sources, such as a third-party system 170, theinternet or World Wide Web, or other suitable sources. Although thisdisclosure describes querying the social-networking system 160 in aparticular manner, this disclosure contemplates querying thesocial-networking system 160 in any suitable manner.

In particular embodiments, the typeahead processes described herein maybe applied to search queries entered by a user. As an example and not byway of limitation, as a user enters text characters into a search field,a typeahead process may attempt to identify one or more user nodes 202,concept nodes 204, or edges 206 that match the string of charactersentered search field as the user is entering the characters. As thetypeahead process receives requests or calls including a string orn-gram from the text query, the typeahead process may perform or causesto be performed a search to identify existing social-graph elements(i.e., user nodes 202, concept nodes 204, edges 206) having respectivenames, types, categories, or other identifiers matching the enteredtext. The typeahead process may use one or more matching algorithms toattempt to identify matching nodes or edges. When a match or matches arefound, the typeahead process may transmit a response to the user'sclient system 130 that may include, for example, the names (namestrings) of the matching nodes as well as, potentially, other metadataassociated with the matching nodes. The typeahead process may thendisplay a drop-down menu 300 that displays names of matching existingprofile pages and respective user nodes 202 or concept nodes 204, anddisplays names of matching edges 206 that may connect to the matchinguser nodes 202 or concept nodes 204, which the user can then click on orotherwise select thereby confirming the desire to search for the matcheduser or concept name corresponding to the selected node, or to searchfor users or concepts connected to the matched users or concepts by thematching edges. Alternatively, the typeahead process may simplyauto-populate the form with the name or other identifier of thetop-ranked match rather than display a drop-down menu 300. The user maythen confirm the auto-populated declaration simply by keying “enter” ona keyboard or by clicking on the auto-populated declaration. Upon userconfirmation of the matching nodes and edges, the typeahead process maytransmit a request that informs the social-networking system 160 of theuser's confirmation of a query containing the matching social-graphelements. In response to the request transmitted, the social-networkingsystem 160 may automatically (or alternately based on an instruction inthe request) call or otherwise search a social-graph database for thematching social-graph elements, or for social-graph elements connectedto the matching social-graph elements as appropriate. Although thisdisclosure describes applying the typeahead processes to search queriesin a particular manner, this disclosure contemplates applying thetypeahead processes to search queries in any suitable manner.

Parsing Queries Using Context-Free Grammar Models

FIGS. 4A-4B illustrate example queries of the social network. Inparticular embodiments, the social-networking system 160 may generateone or more structured queries comprising query tokens that correspondto one or more identified social-graph elements in response to a textquery received from a first user (i.e., the querying user). FIGS. 4A-4Billustrate various example text queries in query field 350 and variousstructured queries generated in response in drop-down menus 300. Byproviding suggested structured queries in response to a user's textquery, the social-networking system 160 may provide a powerful way forusers of the online social network to search for elements represented inthe social graph 200 based on their social-graph attributes and theirrelation to various social-graph elements. Structured queries may allowa querying user to search for content that is connected to particularusers or concepts in the social graph 200 by particular edge types. Asan example and not by way of limitation, the social-networking system160 may receive a substantially unstructured text query from a firstuser. In response, the social-networking system 160 (via, for example, aserver-side element detection process) may access the social graph 200and then parse the text query to identify social-graph elements thatcorresponded to n-grams from the text query. The social-networkingsystem 160 may identify these corresponding social-graph elements bydetermining a probability for each n-gram that it corresponds to aparticular social-graph element. The social-networking system 160 maythen access a grammar model, such as a context-free grammar model. Theidentified social-graph elements may be used as terminal tokens (“querytokens”) in the grammars, and each grammar may then be scored. Grammarswith a score greater than a threshold score may be used to generatestructured queries that include query tokens referencing the identifiedsocial-graph elements. The structured queries may then be transmitted tothe first user and displayed in a drop-down menu 300 (via, for example,a client-side typeahead process), where the first user can then selectan appropriate query to search for the desired content. Some of theadvantages of using the structured queries described herein includefinding users of the online social networking based upon limitedinformation, bringing together virtual indexes of content from theonline social network based on the relation of that content to varioussocial-graph elements, or finding content related to you and/or yourfriends. Although this disclosure describes and FIGS. 4A-4B illustrategenerating particular structured queries in a particular manner, thisdisclosure contemplates generating any suitable structured queries inany suitable manner.

In particular embodiments, the social-networking system 160 may receivefrom a querying/first user (corresponding to a first user node 202) asubstantially unstructured text query. As an example and not by way oflimitation, a first user may want to search for other users who: (1) arefirst-degree friends of the first user; and (2) are associated withStanford University (i.e., the user nodes 202 are connected by an edge206 to the concept node 204 corresponding to the school “Stanford”). Thefirst user may then enter a text query “friends stanford” into queryfield 350, as illustrated in FIGS. 4A-4B. As the first user enters thistext query into query field 350, the social-networking system 160 mayprovide various suggested structured queries, as illustrated indrop-down menus 300. As used herein, a substantially unstructured textquery refers to a simple text string inputted by a user. The text querymay, of course, be structured with respect to standard language/grammarrules (e.g. English language grammar). However, the text query willordinarily be unstructured with respect to social-graph elements. Inother words, a simply text query will not ordinarily include embeddedreferences to particular social-graph elements. Thus, as used herein, astructured query refers to a query that contains references toparticular social-graph elements, allowing the search engine to searchbased on the identified elements. Although this disclosure describesreceiving particular queries in a particular manner, this disclosurecontemplates receiving any suitable queries in any suitable manner.

In particular embodiments, social-networking system 160 may parse thesubstantially unstructured text query (also simply referred to as asearch query) received from the first user (i.e., the querying user) toidentify one or more n-grams. In general, an n-gram is a contiguoussequence of n items from a given sequence of text or speech. The itemsmay be characters, phonemes, syllables, letters, words, base pairs,prefixes, or other identifiable items from the sequence of text orspeech. The n-gram may comprise one or more characters of text (letters,numbers, punctuation, etc.) entered by the querying user. An n-gram ofsize one can be referred to as a “unigram,” of size two can be referredto as a “bigram” or “digram,” of size three can be referred to as a“trigram,” and so on. Each n-gram may include one or more parts from thetext query received from the querying user. In particular embodiments,each n-gram may comprise a character string (e.g., one or morecharacters of text) entered by the first user. As an example and not byway of limitation, the social-networking system 160 may parse the textquery “friends stanford” to identify the following n-grams: friends;stanford; friends stanford. As another example and not by way oflimitation, the social-networking system 160 may parse the text query“friends in palo alto” to identify the following n-grams: friends; in;palo; alto; friends in; in palo; palo alto; friend in palo; in paloalso; friends in palo alto. In particular embodiments, each n-gram maycomprise a contiguous sequence of n items from the text query. Althoughthis disclosure describes parsing particular queries in a particularmanner, this disclosure contemplates parsing any suitable queries in anysuitable manner.

In particular embodiments, social-networking system 160 may determine orcalculate, for each n-gram identified in the text query, a score thatthe n-gram corresponds to a social-graph element. The score may be, forexample, a confidence score, a probability, a quality, a ranking,another suitable type of score, or any combination thereof. As anexample and not by way of limitation, the social-networking system 160may determine a probability score (also referred to simply as a“probability”) that the n-gram corresponds to a social-graph element,such as a user node 202, a concept node 204, or an edge 206 of socialgraph 200. The probability score may indicate the level of similarity orrelevance between the n-gram and a particular social-graph element.There may be many different ways to calculate the probability. Thepresent disclosure contemplates any suitable method to calculate aprobability score for an n-gram identified in a search query. Inparticular embodiments, the social-networking system 160 may determine aprobability, p, that an n-gram corresponds to a particular social-graphelement. The probability, p, may be calculated as the probability ofcorresponding to a particular social-graph element, k, given aparticular search query, X. In other words, the probability may becalculated as p=(k|X) As an example and not by way of limitation, aprobability that an n-gram corresponds to a social-graph element maycalculated as an probability score denoted as p_(i,j,k). The input maybe a text query X=(x₁,x₂, . . . ,x_(N)), and a set of classes. For each(i:j) and a class k, the social-networking system 160 may computep_(i,j,k)=p(class(x_(i:j))=k|X). As an example and not by way oflimitation, the n-gram “stanford” could be scored with respect to thefollowing social-graph elements as follows: school “StanfordUniversity”=0.7; location “Stanford, California”=0.2; user “AllenStanford”=0.1. As another example and not by way of limitation, then-gram “friends” could be scored with respect to the followingsocial-graph elements as follows: user “friends”=0.9; television show“Friends”=0.1. In particular embodiments, the social-networking system160 may user a forward-backward algorithm to determine the probabilitythat a particular n-gram corresponds to a particular social-graphelement. For a given n-gram within a text query, the social-networkingsystem 160 may use both the preceding and succeeding n-grams todetermine which particular social-graph elements correspond to the givenn-gram. Although this disclosure describes determining whether n-gramscorrespond to social-graph elements in a particular manner, thisdisclosure contemplates determining whether n-grams correspond tosocial-graph elements in any suitable manner. Moreover, although thisdisclosure describes determining whether an n-gram corresponds to asocial-graph element using a particular type of score, this disclosurecontemplates determining whether an n-gram corresponds to a social-graphelement using any suitable type of score.

In particular embodiments, social-networking system 160 may identify oneor more edges 206 having a probability greater than an edge-thresholdprobability. Each of the identified edges 206 may correspond to at leastone of the n-grams. As an example and not by way of limitation, then-gram may only be identified as corresponding to an edge k ifp_(i,j,k)>p_(edge-threshold). Furthermore, each of the identified edges206 may be connected to at least one of the identified nodes. In otherwords, the social-networking system 160 may only identify edges 206 oredge-types that are connected to user nodes 202 or concept nodes 204that have previously been identified as corresponding to a particularn-gram. Edges 206 or edge-types that are not connected to any previouslyidentified node are typically unlikely to correspond to a particularn-gram in a search query. By filtering out or ignoring these edges 206and edge-types, the social-networking system 160 may more efficientlysearch the social graph for relevant social-graph elements. As anexample and not by way of limitation, referencing FIG. 2, for a textquery containing “went to Stanford,” where an identified concept node204 is the school “Stanford,” the social-networking system 160 mayidentify the edges 206 corresponding to “worked at” and the edges 206corresponding to “attended,” both of which are connected to the conceptnode 204 for “Stanford.” Thus, the n-gram “went to” may be identified ascorresponding to these edges 206. However, for the same text query, thesocial-networking system 160 may not identify the edges 206corresponding to “like” or “fan” in the social graph 200 because the“Stanford” node does not have any such edges connected to it. Althoughthis disclosure describes identifying edges 206 that corresponding ton-grams in a particular manner, this disclosure contemplates identifyingedges 206 that corresponding to n-grams in any suitable manner.

In particular embodiments, social-networking system 160 may identify oneor more user nodes 202 or concept nodes 204 having a probability greaterthan a node-threshold probability. Each of the identified nodes maycorrespond to at least one of the n-grams. As an example and not by wayof limitation, the n-gram may only be identified as corresponding to anode k if p_(i,j,k)>p_(node-threshold). Furthermore, each of theidentified user nodes 202 or concept nodes 204 may be connected to atleast one of the identified edges 206. In other words, thesocial-networking system 160 may only identify nodes or nodes-types thatare connected to edges 206 that have previously been identified ascorresponding to a particular n-gram. Nodes or node-types that are notconnected to any previously identified edges 206 are typically unlikelyto correspond to a particular n-gram in a search query. By filtering outor ignoring these nodes and node-types, the social-networking system 160may more efficiently search the social graph for relevant social-graphelements. As an example and not by way of limitation, for a text querycontaining “worked at Apple,” where an identified edge 206 is “workedat,” the social-networking system 160 may identify the concept node 204corresponding to the company APPLE, INC., which may have multiple edges206 of “worked at” connected to it. However, for the same text query,the social-networking system 160 may not identify the concept node 204corresponding to the fruit-type “apple,” which may have multiple “like”or “fan” edges connected to it, but no “worked at” edge connections. Inparticular embodiments, the node-threshold probability may differ foruser nodes 202 and concept nodes 204 The n-gram may be identified ascorresponding to a user node 302 k_(user) ifp_(i,j,k)>p_(user-node-threshold), while the n-gram may be identified ascorresponding to a concept node 304 k_(concept) ifp_(i,j,k)>p_(concept-node-threshold). In particular embodiments, thesocial-networking system 160 may only identify nodes that are within athreshold degree of separation of the user node 202 corresponding to thefirst user (i.e., the querying user). The threshold degree of separationmay be, for example, one, two, three, or all. Although this disclosuredescribes identifying nodes that corresponding to n-grams in aparticular manner, this disclosure contemplates identifying nodes thatcorresponding to n-grams in any suitable manner.

In particular embodiments, the social-networking system 160 may access acontext-free grammar model comprising a plurality of grammars. Eachgrammar of the grammar model may comprise one or more non-terminalsymbols that may be replaced by query tokens. A grammar model is a setof formation rules for strings in a formal language. To generate astring in the language, one begins with a string consisting of only asingle start symbol. The production rules are then applied in any order,until a string that contains neither the start symbol nor designatednon-terminal symbols is produced. In a context-free grammar, theproduction of each non-terminal symbol of the grammar is independent ofwhat is produced by other non-terminal symbols of the grammar. Thenon-terminal symbols may be replaced with terminal symbols (i.e.,terminal tokens or query tokens). Some of the query tokens maycorrespond to identified nodes or identified edges, as describedpreviously. A string generated by the grammar may then be used as astructured query containing references to the identified nodes oridentified edges. A context-free grammar is a grammar in which theleft-hand side of each production rule consists of only a singlenon-terminal symbol. A probabilistic context-free grammar is a tuple

Σ,N,S,P

, where the disjoint sets Σ and N specify the terminal and non-terminalsymbols, respectively, with SεN being the start symbol. P is the set ofproductions, which take the form E→ξ(p), with EεN, ξεN, ξε(Σ∪N)⁺, andp=Pr(E→ξ), the probability that E will be expanded into the string ξ.The sum of probabilities p over all expansions of a given non-terminal Emust be one. Although this disclosure describes accessing particulargrammars, this disclosure contemplates any suitable grammars.

In particular embodiments, the social-networking system 160 may identifyone or more grammars having query tokens corresponding to the previouslyidentified nodes and edges. In other words, if an identified node oridentified edge may be used as a query token in a particular grammar,that grammar may be identified by the social-networking system 160 as apossible grammar to use for generating a structured query. This iseffectively a type of bottom-up parsing, where the possible query tokensare used to determine the applicable grammar to apply to the query. Asan example and not by way of limitation, an example grammar may be:[user] [user-filter] [school]. The non-terminal symbols [user],[user-filter], and [school] could then be determined based n-grams inthe received text query. For the text query “friends stanford”, thisquery could be parsed by using the grammar as, for example, “[friends][who go to] [Stanford University]” or “[friends] [who work at] [StanfordUniversity]”. As another example and not by way of limitation, anexample grammar may be [user] [user-filter][location]. For the textquery “friends stanford”, this query could be parsed by using thegrammar as, for example, “[friends] [who live in] [Stanford,California]”. In both the example cases above, if the n-grams of thereceived text query could be used as query tokens in the grammars, thenthese grammars may be identified by the social-networking system 160.Similarly, if the received text query comprises n-grams that could notbe used as query tokens in the grammar, that grammar may not beidentified. Although this disclosure describes identifying particulargrammars in a particular manner, this disclosure contemplatesidentifying any suitable grammars in any suitable manner.

In particular embodiments, the social-networking system 160 maydetermine a score for each identified grammar. The score may be, forexample, a confidence score, a probability, a quality, a ranking,another suitable type of score, or any combination thereof. The scoremay be based on the individual scores or probabilities associated withthe query tokens of the grammar. A grammar may have a higher relativescore if it uses query tokens with relatively higher individual scores.As an example and not by way of limitation, continuing with the priorexamples, the n-gram “stanford” could be scored with respect to thefollowing social-graph elements as follows: school “StanfordUniversity”=0.7; location “Stanford, California”=0.2; user “AllenStanford”=0.1. The n-gram “friends” could be scored with respect to thefollowing social-graph elements as follows: user “friends”=0.9;television show “Friends”=0.1. Thus, the grammar [user] [user-filter][school] may have a relatively high score if it uses the query tokensfor the user “friends” and the school “Stanford University” (generating,for example, the string “friends who go to Stanford University”), bothof which have relatively high individual scores. In contrast, thegrammar [user] [user-filter] [user] may have relatively low score if ituses the query tokens for the user “friends” and the user “AllenStanford” (generating, for example, the string “friends of AllenStanford”), since the latter query token has a relatively low individualscore. Although this disclosure describes determining particular scoresfor particular grammars in a particular manner, this disclosurecontemplates determining any suitable scores for any suitable grammarsin any suitable manner.

In particular embodiments, the social-networking system 160 maydetermine the score for an identified grammar based on the relevance ofthe social-graph elements corresponding to the query tokens of thegrammar to the querying user (i.e., the first user, corresponding to afirst user node 202). User nodes 202 and concept nodes 204 that areconnected to the first user node 202 directly by an edge 206 may beconsidered relevant to the first user. Thus, grammars comprising querytokens corresponding to these relevant nodes and edges may be consideredmore relevant to the querying user. As an example and not by way oflimitation, a concept node 204 connected by an edge 206 to a first usernode 202 may be considered relevant to the first user node 202. As usedherein, when referencing a social graph 200 the term “connected” means apath exists within the social graph 200 between two nodes, wherein thepath may comprise one or more edges 206 and zero or more intermediarynodes. In particular embodiments, nodes that are connected to the firstuser node 202 via one or more intervening nodes (and therefore two ormore edges 206) may also be considered relevant to the first user.Furthermore, in particular embodiments, the closer the second node is tothe first user node, the more relevant the second node may be consideredto the first user node. That is, the fewer edges 206 separating thefirst user node 202 from a particular user node 202 or concept node 204(i.e., the fewer degrees of separation), the more relevant that usernode 202 or concept node 204 may be considered to the first user. As anexample and not by way of limitation, as illustrated in FIG. 2, theconcept node 204 corresponding to the school “Stanford” is connected tothe user node 202 corresponding to User “C,” and thus the concept“Stanford” may be considered relevant to User “C.” As another exampleand not by way of limitation, the user node 202 corresponding to User“A” is connected to the user node 202 corresponding to User “C” via oneintermediate node and two edges 206 (i.e., the intermediated user node202 corresponding to User “B”), and thus User “A” may be consideredrelevant to User “C,” but because the user node 202 for User “A” is asecond-degree connection with respect to User “C,” that particularconcept node 204 may be considered less relevant than a user node 202that is connected to the user node for User “C” by a single edge 206,such as, for example, the user node 202 corresponding to User “B.” Asyet another example and not by way of limitation, the concept node for“Online Poker” (which is an online multiplayer game) is not connected tothe user node for User “C” by any pathway in social graph 200, and thusthe concept “Online Poker” may not be considered relevant to User “C.”In particular embodiments, a second node may only be considered relevantto the first user if the second node is within a threshold degree ofseparation of the first user node 202. As an example and not by way oflimitation, if the threshold degree of separation is three, then theuser node 202 corresponding to User “D” may be considered relevant tothe concept node 204 corresponding to the recipe “Chicken Parmesan,”which are within three degrees of each other on social graph 200illustrated in FIG. 2. However, continuing with this example, theconcept node 204 corresponding to the application “All About Recipes”would not be considered relevant to the user node 202 corresponding toUser “D” because these nodes are four degrees apart in the social graph200. Although this disclosure describes determining whether particularsocial-graph elements (and thus their corresponding query tokens) arerelevant to each other in a particular manner, this disclosurecontemplates determining whether any suitable social-graph elements arerelevant to each other in any suitable manner. Moreover, although thisdisclosure describes determining whether particular query tokenscorresponding to user nodes 202 and concept nodes 204 are relevant to aquerying user, this disclosure contemplates similarly determiningwhether any suitable query token (and thus any suitable node) isrelevant to any other suitable user.

In particular embodiments, the social-networking system 160 maydetermine the score for an identified grammar based social-graphinformation corresponding to the query tokens of the grammar. As anexample and not by way of limitation, when determining a probability, p,that an n-gram corresponds to a particular social-graph element, thecalculation of the probability may also factor in social-graphinformation. Thus, the probability of corresponding to a particularsocial-graph element, k, given a particular search query, X, andsocial-graph information, G, may be calculated as p=(k|X,G). Theindividual probabilities for the identified nodes and edges may then beused to determine the score for a grammar using those social-graphelements as query tokens. In particular embodiments, the score for anidentified grammar may be based on the degree of separation between thefirst user node 202 and the particular social-graph element used as aquery token in the grammar. Grammars with query tokens corresponding tosocial-graph elements that are closer in the social graph 200 to thequerying user (i.e., fewer degrees of separation between the element andthe first user node 202) than a social-graph element that is furtherfrom the user (i.e., more degrees of separation). As an example and notby way of limitation, referencing FIG. 2, if user “B” inputs a textquery of “chicken,” a grammar with a query token corresponding to theconcept node 204 for the recipe “Chicken Parmesan,” which is connectedto user “B” by an edge 206, may have a relatively higher score than agrammar with a query token corresponding to other nodes associated withthe n-gram chicken (e.g., concept nodes 204 corresponding to “chickennuggets,” or “funky chicken dance”) that are not connected to user “B”in the social graph 200. In particular embodiments, the score for anidentified grammar may be based on the identified edges 206corresponding to the query tokens of the grammar. If thesocial-networking system 160 has already identified one or more edgesthat correspond to n-grams in a received text query, those identifiededges may then be considered when determining the score for a particularparsing of the text query by the grammar. If a particular grammarcomprises query tokens that correspond to both identified nodes andidentified edges, if the identified nodes are not actually connected toany of the identified edges, that particular grammar may be assigned azero or null score. In particular embodiments, the score for anidentified grammar may be based on the number of edges 206 connected tothe node corresponding to a query token of the grammar. Grammarscomprising query tokens that corresponding to nodes with more connectingedges 206 may be more popular and more likely to be a target of a searchquery. As an example and not by way of limitation, if the concept node204 for “Stanford, California” is only connected by five edges while theconcept node 204 for “Stanford University” is connected by five-thousandedges, when determining the score for grammars containing query tokenscorresponding to either of these nodes, the social-networking system 160may determine that the grammar referencing the concept node 204 for“Stanford University” has a relatively higher score than a grammarreferencing the concept node 204 for “Stanford, California” because ofthe greater number of edges connected to the former concept node 204. Inparticular embodiments, the score for an identified grammar may be basedon the search history associate with the first user (i.e., the queryinguser). Grammars with query tokens corresponding to nodes that the firstuser has previously accessed, or are relevant to the nodes the firstuser has previously accessed, may be more likely to be the target of thefirst user's search query. Thus, these grammars may be given a higherscore. As an example and not by way of limitation, if first user haspreviously visited the “Stanford University” profile page but has nevervisited the “Stanford, California” profile page, when determining thescore for grammars with query tokens corresponding to these concepts,the social-networking system 160 may determine that the concept node 204for “Stanford University” has a relatively high score, and thus thegrammar using the corresponding query token, because the querying userhas previously accessed the concept node 204 for the school. As anotherexample and not by way of limitation, if the first user has previouslyvisited the concept-profile page for the television show “Friends,” whendetermining the score for the grammar with the query token correspondingto that concept, the social-networking system 160 may determine that theconcept node 204 corresponding to the television show “Friends” has arelatively high score, and thus the grammar using the correspondingquery token, because the querying user has previously accessed theconcept node 204 for that television show. Although this disclosuredescribes determining scores for particular grammars based on particularsocial-graph information in a particular manner, this disclosurecontemplates determining scores for any suitable grammars based on anysuitable social-graph information in any suitable manner.

In particular embodiments, social-networking system 160 may select oneor more grammars having a score greater than a grammar-threshold score.Each of the selected grammars may contain query tokens that correspondto at least one of the identified nodes or identified edges (whichcorrespond to n-grams of the received text query). In particularembodiments, the grammars may be ranked based on their determinedscores, and only grammars within a threshold rank may be selected (e.g.,top seven). Although this disclosure describes selecting grammars in aparticular manner, this disclosure contemplates selecting grammars inany suitable manner.

In particular embodiments, social-networking system 160 may generate oneor more structured queries corresponding to an identified grammar havinga score greater than a grammar-threshold score. Each structure query maybe based on a string generated by the corresponding identified grammar.As an example and not by way of limitation, in response to the textquery “friends stanford”, the grammar [user] [user-filter] [school] maygenerate a string “friends who go to Stanford University”, where thenon-terminal tokens [user], [user-filter], [school] of the grammar havebeen replaced by the terminal tokens [friends], [who go to], and[Stanford University], respectively, to generate the string. Eachstructured query may comprise query tokens corresponding to thecorresponding identified grammar, where these query tokens correspond toone or more of the identified edges 206 and one or more of theidentified nodes. Generating structured queries is described more below.

FIG. 5 illustrates an example method 500 for using a context-freegrammar model to generate structured search queries. The method maybegin at step 510, where the social-networking system 160 may access asocial graph 200 comprising a plurality of nodes and a plurality ofedges 206 connecting the nodes. The nodes may comprise a first user node202 and a plurality of second nodes (one or more user nodes 202,concepts nodes 204, or any combination thereof). At step 520, thesocial-networking system 160 may receive from the first user asubstantially unstructured text query. The text query may comprise oneor more n-grams. At step 530, the social-networking system 160 mayidentify edges and second nodes corresponding to the n-grams. At step540, the social-networking system 160 may access a context-free grammarmodel comprising a plurality of grammars. Each grammar may comprise oneor more query tokens. At step 550, the social-networking system 160 mayidentify grammars having query tokens corresponding to the identifiednodes or identified edges. At step 560, the social-networking system 160may determine a score for each identified grammar. This score may bebased on a variety of factors. At step 570, the social-networking systemmay generate one or more structured queries based on the identifiedgrammars. Each structured query may correspond to an indentified grammarhaving a score greater than a grammar-threshold score, and may comprisethe query tokens of the corresponding identified grammar. The querytokens of the structured query may correspond to at least one of theidentified second nodes or identified edges. Particular embodiments mayrepeat one or more steps of the method of FIG. 5, where appropriate.Although this disclosure describes and illustrates particular steps ofthe method of FIG. 5 as occurring in a particular order, this disclosurecontemplates any suitable steps of the method of FIG. 5 occurring in anysuitable order. Moreover, although this disclosure describes andillustrates particular components, devices, or systems carrying outparticular steps of the method of FIG. 5, this disclosure contemplatesany suitable combination of any suitable components, devices, or systemscarrying out any suitable steps of the method of FIG. 5.

Generating Structured Search Queries

In particular embodiments, social-networking system 160 may generate oneor more structured queries that each comprise the query tokens of thecorresponding grammar, where the query tokens may correspond to one ormore of the identified user nodes 202 or one or more of the identifiededges 206. The generated structured queries may be based on context-freegrammars, as described previously. This type of structured search querymay allow the social-networking system 160 to more efficiently searchfor resources and content related to the online social network (such as,for example, profile pages) by searching for content connected to orotherwise related to the identified user nodes 202 and the identifiededges 206. As an example and not by way of limitation, in response tothe text query, “show me friends of my girlfriend,” thesocial-networking system 160 may generate a structured query “Friends ofStephanie,” where “Friends” and “Stephanie” in the structured query arereferences corresponding to particular social-graph elements. Thereference to “Stephanie” would correspond to a particular user node 202,while the reference to “friends” would correspond to “friend” edges 206connecting that user node 202 to other user nodes 202 (i.e., edges 206connecting to “Stephanie's” first-degree friends). When executing thisstructured query, the social-networking system 160 may identify one ormore user nodes 202 connected by “friend” edges 206 to the user node 202corresponding to “Stephanie.” In particular embodiments, thesocial-networking system 160 may generate a plurality of structuredqueries, where the structured queries may comprise references todifferent identified user nodes 202 or different identified edges 206.As an example and not by way of limitation, in response to the textquery, “photos of cat,” the social-networking system 160 may generate afirst structured query “Photos of Catey” and a second structured query“Photos of Catherine,” where “Photos” in the structured query is areference corresponding to a particular social-graph element, and where“Catey” and “Catherine” are references to two different user nodes 202.When executing either of these structured queries, the social-networkingsystem 160 may identify one or more concept nodes 204 corresponding tophotos that are connected to the identified user nodes 202 by edges 206.Although this disclosure describes generating particular structuredqueries in a particular manner, this disclosure contemplates generatingany suitable structured queries in any suitable manner.

In particular embodiments, social-networking system 160 may generate oneor more structured queries that each comprise query tokens correspondingto the identified concept nodes 204 and one or more of the identifiededges 206. This type of structured search query may allow thesocial-networking system 160 to more efficiently search for resourcesand content related to the online social network (such as, for example,profile pages) by search for content connected to or otherwise relatedto the identified concept nodes 204 and the identified edges 206. As anexample and not by way of limitation, in response to the text query,“friends who like facebook,” the social-networking system 160 maygenerate a structured query “Friends who like Facebook,” where“Friends,” like,” and “Facebook” in the structured query are querytokens corresponding to particular social-graph elements as describedpreviously (i.e., a “friend” edge 206, a “like” edge 206, and a“Facebook” concept node 204). In particular embodiments, thesocial-networking system 160 may generate a plurality of structuredqueries, where the structured queries may comprise references todifferent identified concept nodes 204 or different identified edges206. As an example and not by way of limitation, continuing with theprevious example, in addition to the structured query “Friends who likeFacebook,” the social-networking system 160 may also generate astructured query “Friends who like Facebook Culinary Team,” where“Facebook Culinary Team” in the structured query is a query tokencorresponding to yet another social-graph element. In particularembodiments, social-networking system 160 may rank the generatedstructured queries. The structured queries may be ranked based on avariety of factors. Although this disclosure describes generatingparticular structured queries in a particular manner, this disclosurecontemplates generating any suitable structured queries in any suitablemanner.

In particular embodiments, social-networking system 160 may transmit oneor more of the structured queries to the first user (i.e., the queryinguser). As an example and not by way of limitation, after the structuredqueries are generated, the social-networking system 160 may transmit oneor more of the structured queries as a response (which may utilize AJAXor other suitable techniques) to the user's client system 130 that mayinclude, for example, the names (name strings) of the referencedsocial-graph elements, other query limitations (e.g., Boolean operators,etc.), as well as, potentially, other metadata associated with thereferenced social-graph elements. The web browser 132 on the queryinguser's client system 130 may display the transmitted structured queriesin a drop-down menu 300, as illustrated in FIGS. 4A-4B. In particularembodiments, the transmitted queries may be presented to the queryinguser in a ranked order, such as, for example, based on a rank previouslydetermined as described above. Structured queries with better rankingsmay be presented in a more prominent position. Furthermore, inparticular embodiments, only structured queries above a threshold rankmay be transmitted or displayed to the querying user. As an example andnot by way of limitation, as illustrated in FIGS. 4A-4B, the structuredqueries may be presented to the querying user in a drop-down menu 300where higher ranked structured queries may be presented at the top ofthe menu, with lower ranked structured queries presented in descendingorder down the menu. In the examples illustrated in FIGS. 4A-4B, onlythe seven highest ranked queries are transmitted and displayed to theuser. In particular embodiments, one or more references in a structuredquery may be highlighted in order to indicate its correspondence to aparticular social-graph element. As an example and not by way oflimitation, as illustrated in FIGS. 4A-4B, the references to “StanfordUniversity” and “Stanford, California” may be highlighted in thestructured queries to indicate that it corresponds to a particularconcept node 204. Similarly, the references to “Friends”, “like”, “workat”, and “go to” in the structured queries presented in drop-down menu300 could also be highlighted to indicate that they correspond toparticular edges 206. Although this disclosure describes transmittingparticular structured queries in a particular manner, this disclosurecontemplates transmitting any suitable structured queries in anysuitable manner.

In particular embodiments, social-networking system 160 may receive fromthe first user (i.e., the querying user) a selection of one of thestructured queries. As an example and not by way of limitation, the webbrowser 132 on the querying user's client system 130 may display thetransmitted structured queries in a drop-down menu 300, as illustratedin FIGS. 4A-4B, which the user may then click on or otherwise select(e.g., by simply keying “enter” on his keyboard) to indicate theparticular structured query the user wants the social-networking system160 to execute. Upon selecting the particular structured query, theuser's client system 130 may call or otherwise instruct to thesocial-networking system 160 to execute the selected structured query.Although this disclosure describes receiving selections of particularstructured queries in a particular manner, this disclosure contemplatesreceiving selections of any suitable structured queries in any suitablemanner.

More information on structured search queries may be found in U.S.patent application Ser. No. 13/556,072, filed 23 Jul. 2012, which isincorporated by reference.

Systems and Methods

FIG. 6 illustrates an example computer system 600. In particularembodiments, one or more computer systems 600 perform one or more stepsof one or more methods described or illustrated herein. In particularembodiments, one or more computer systems 600 provide functionalitydescribed or illustrated herein. In particular embodiments, softwarerunning on one or more computer systems 600 performs one or more stepsof one or more methods described or illustrated herein or providesfunctionality described or illustrated herein. Particular embodimentsinclude one or more portions of one or more computer systems 600.Herein, reference to a computer system may encompass a computing device,where appropriate. Moreover, reference to a computer system mayencompass one or more computer systems, where appropriate.

This disclosure contemplates any suitable number of computer systems600. This disclosure contemplates computer system 600 taking anysuitable physical form. As example and not by way of limitation,computer system 600 may be an embedded computer system, a system-on-chip(SOC), a single-board computer system (SBC) (such as, for example, acomputer-on-module (COM) or system-on-module (SOM)), a desktop computersystem, a laptop or notebook computer system, an interactive kiosk, amainframe, a mesh of computer systems, a mobile telephone, a personaldigital assistant (PDA), a server, a tablet computer system, or acombination of two or more of these. Where appropriate, computer system600 may include one or more computer systems 600; be unitary ordistributed; span multiple locations; span multiple machines; spanmultiple data centers; or reside in a cloud, which may include one ormore cloud components in one or more networks. Where appropriate, one ormore computer systems 600 may perform without substantial spatial ortemporal limitation one or more steps of one or more methods describedor illustrated herein. As an example and not by way of limitation, oneor more computer systems 600 may perform in real time or in batch modeone or more steps of one or more methods described or illustratedherein. One or more computer systems 600 may perform at different timesor at different locations one or more steps of one or more methodsdescribed or illustrated herein, where appropriate.

In particular embodiments, computer system 600 includes a processor 602,memory 604, storage 606, an input/output (I/O) interface 608, acommunication interface 610, and a bus 612. Although this disclosuredescribes and illustrates a particular computer system having aparticular number of particular components in a particular arrangement,this disclosure contemplates any suitable computer system having anysuitable number of any suitable components in any suitable arrangement.

In particular embodiments, processor 602 includes hardware for executinginstructions, such as those making up a computer program. As an exampleand not by way of limitation, to execute instructions, processor 602 mayretrieve (or fetch) the instructions from an internal register, aninternal cache, memory 604, or storage 606; decode and execute them; andthen write one or more results to an internal register, an internalcache, memory 604, or storage 606. In particular embodiments, processor602 may include one or more internal caches for data, instructions, oraddresses. This disclosure contemplates processor 602 including anysuitable number of any suitable internal caches, where appropriate. Asan example and not by way of limitation, processor 602 may include oneor more instruction caches, one or more data caches, and one or moretranslation lookaside buffers (TLBs). Instructions in the instructioncaches may be copies of instructions in memory 604 or storage 606, andthe instruction caches may speed up retrieval of those instructions byprocessor 602. Data in the data caches may be copies of data in memory604 or storage 606 for instructions executing at processor 602 tooperate on; the results of previous instructions executed at processor602 for access by subsequent instructions executing at processor 602 orfor writing to memory 604 or storage 606; or other suitable data. Thedata caches may speed up read or write operations by processor 602. TheTLBs may speed up virtual-address translation for processor 602. Inparticular embodiments, processor 602 may include one or more internalregisters for data, instructions, or addresses. This disclosurecontemplates processor 602 including any suitable number of any suitableinternal registers, where appropriate. Where appropriate, processor 602may include one or more arithmetic logic units (ALUs); be a multi-coreprocessor; or include one or more processors 602. Although thisdisclosure describes and illustrates a particular processor, thisdisclosure contemplates any suitable processor.

[65] In particular embodiments, memory 604 includes main memory forstoring instructions for processor 602 to execute or data for processor602 to operate on. As an example and not by way of limitation, computersystem 600 may load instructions from storage 606 or another source(such as, for example, another computer system 600) to memory 604.Processor 602 may then load the instructions from memory 604 to aninternal register or internal cache. To execute the instructions,processor 602 may retrieve the instructions from the internal registeror internal cache and decode them. During or after execution of theinstructions, processor 602 may write one or more results (which may beintermediate or final results) to the internal register or internalcache. Processor 602 may then write one or more of those results tomemory 604. In particular embodiments, processor 602 executes onlyinstructions in one or more internal registers or internal caches or inmemory 604 (as opposed to storage 606 or elsewhere) and operates only ondata in one or more internal registers or internal caches or in memory604 (as opposed to storage 606 or elsewhere). One or more memory buses(which may each include an address bus and a data bus) may coupleprocessor 602 to memory 604. Bus 612 may include one or more memorybuses, as described below. In particular embodiments, one or more memorymanagement units (MMUs) reside between processor 602 and memory 604 andfacilitate accesses to memory 604 requested by processor 602. Inparticular embodiments, memory 604 includes random access memory (RAM).This RAM may be volatile memory, where appropriate Where appropriate,this RAM may be dynamic RAM (DRAM) or static RAM (SRAM). Moreover, whereappropriate, this RAM may be single-ported or multi-ported RAM. Thisdisclosure contemplates any suitable RAM. Memory 604 may include one ormore memories 604, where appropriate. Although this disclosure describesand illustrates particular memory, this disclosure contemplates anysuitable memory.

In particular embodiments, storage 606 includes mass storage for data orinstructions. As an example and not by way of limitation, storage 606may include a hard disk drive (HDD), a floppy disk drive, flash memory,an optical disc, a magneto-optical disc, magnetic tape, or a UniversalSerial Bus (USB) drive or a combination of two or more of these. Storage606 may include removable or non-removable (or fixed) media, whereappropriate. Storage 606 may be internal or external to computer system600, where appropriate. In particular embodiments, storage 606 isnon-volatile, solid-state memory. In particular embodiments, storage 606includes read-only memory (ROM). Where appropriate, this ROM may bemask-programmed ROM, programmable ROM (PROM), erasable PROM (EPROM),electrically erasable PROM (EEPROM), electrically alterable ROM (EAROM),or flash memory or a combination of two or more of these. Thisdisclosure contemplates mass storage 606 taking any suitable physicalform. Storage 606 may include one or more storage control unitsfacilitating communication between processor 602 and storage 606, whereappropriate. Where appropriate, storage 606 may include one or morestorages 606. Although this disclosure describes and illustratesparticular storage, this disclosure contemplates any suitable storage.

In particular embodiments, I/O interface 608 includes hardware,software, or both providing one or more interfaces for communicationbetween computer system 600 and one or more I/O devices. Computer system600 may include one or more of these I/O devices, where appropriate. Oneor more of these I/O devices may enable communication between a personand computer system 600. As an example and not by way of limitation, anI/O device may include a keyboard, keypad, microphone, monitor, mouse,printer, scanner, speaker, still camera, stylus, tablet, touch screen,trackball, video camera, another suitable I/O device or a combination oftwo or more of these. An I/O device may include one or more sensors.This disclosure contemplates any suitable I/O devices and any suitableI/O interfaces 608 for them. Where appropriate, I/O interface 608 mayinclude one or more device or software drivers enabling processor 602 todrive one or more of these I/O devices. I/O interface 608 may includeone or more I/O interfaces 608, where appropriate. Although thisdisclosure describes and illustrates a particular I/O interface, thisdisclosure contemplates any suitable I/O interface.

In particular embodiments, communication interface 610 includeshardware, software, or both providing one or more interfaces forcommunication (such as, for example, packet-based communication) betweencomputer system 600 and one or more other computer systems 600 or one ormore networks. As an example and not by way of limitation, communicationinterface 610 may include a network interface controller (NIC) ornetwork adapter for communicating with an Ethernet or other wire-basednetwork or a wireless NIC (WNIC) or wireless adapter for communicatingwith a wireless network, such as a WI-FI network. This disclosurecontemplates any suitable network and any suitable communicationinterface 610 for it. As an example and not by way of limitation,computer system 600 may communicate with an ad hoc network, a personalarea network (PAN), a local area network (LAN), a wide area network(WAN), a metropolitan area network (MAN), or one or more portions of theInternet or a combination of two or more of these. One or more portionsof one or more of these networks may be wired or wireless. As anexample, computer system 600 may communicate with a wireless PAN (WPAN)(such as, for example, a BLUETOOTH WPAN), a WI-FI network, a WI-MAXnetwork, a cellular telephone network (such as, for example, a GlobalSystem for Mobile Communications (GSM) network), or other suitablewireless network or a combination of two or more of these. Computersystem 600 may include any suitable communication interface 610 for anyof these networks, where appropriate. Communication interface 610 mayinclude one or more communication interfaces 610, where appropriate.Although this disclosure describes and illustrates a particularcommunication interface, this disclosure contemplates any suitablecommunication interface.

In particular embodiments, bus 612 includes hardware, software, or bothcoupling components of computer system 600 to each other. As an exampleand not by way of limitation, bus 612 may include an AcceleratedGraphics Port (AGP) or other graphics bus, an Enhanced Industry StandardArchitecture (EISA) bus, a front-side bus (FSB), a HYPERTRANSPORT (HT)interconnect, an Industry Standard Architecture (ISA) bus, an INFINIBANDinterconnect, a low-pin-count (LPC) bus, a memory bus, a Micro ChannelArchitecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, aPCI-Express (PCIe) bus, a serial advanced technology attachment (SATA)bus, a Video Electronics Standards Association local (VLB) bus, oranother suitable bus or a combination of two or more of these. Bus 612may include one or more buses 612, where appropriate. Although thisdisclosure describes and illustrates a particular bus, this disclosurecontemplates any suitable bus or interconnect.

Herein, a computer-readable non-transitory storage medium or media mayinclude one or more semiconductor-based or other integrated circuits(ICs) (such, as for example, field-programmable gate arrays (FPGAs) orapplication-specific ICs (ASICs)), hard disk drives (HDDs), hybrid harddrives (HHDs), optical discs, optical disc drives (ODDs),magneto-optical discs, magneto-optical drives, floppy diskettes, floppydisk drives (FDDs), magnetic tapes, solid-state drives (SSDs),RAM-drives, SECURE DIGITAL cards or drives, any other suitablecomputer-readable non-transitory storage media, or any suitablecombination of two or more of these, where appropriate. Acomputer-readable non-transitory storage medium may be volatile,non-volatile, or a combination of volatile and non-volatile, whereappropriate.

Herein, “or” is inclusive and not exclusive, unless expressly indicatedotherwise or indicated otherwise by context. Therefore, herein, “A or B”means “A, B, or both,” unless expressly indicated otherwise or indicatedotherwise by context. Moreover, “and” is both joint and several, unlessexpressly indicated otherwise or indicated otherwise by context.Therefore, herein, “A and B” means “A and B, jointly or severally,”unless expressly indicated otherwise or indicated otherwise by context.

The scope of this disclosure encompasses all changes, substitutions,variations, alterations, and modifications to the example embodimentsdescribed or illustrated herein that a person having ordinary skill inthe art would comprehend. The scope of this disclosure is not limited tothe example embodiments described or illustrated herein. Moreover,although this disclosure describes and illustrates respectiveembodiments herein as including particular components, elements,functions, operations, or steps, any of these embodiments may includeany combination or permutation of any of the components, elements,functions, operations, or steps described or illustrated anywhere hereinthat a person having ordinary skill in the art would comprehend.Furthermore, reference in the appended claims to an apparatus or systemor a component of an apparatus or system being adapted to, arranged to,capable of, configured to, enabled to, operable to, or operative toperform a particular function encompasses that apparatus, system,component, whether or not it or that particular function is activated,turned on, or unlocked, as long as that apparatus, system, or componentis so adapted, arranged, capable, configured, enabled, operable, oroperative.

What is claimed is:
 1. A method comprising, by a computing device:receiving, from a client device of a first user, an unstructured textquery inputted by the first user, wherein the unstructured text querycomprises one or more n-grams, the online social network beingassociated with a social graph comprising a plurality of nodes and aplurality of edges connecting the nodes; identifying, based on theunstructured text query, one or more edges and one or more nodes of thesocial graph, each of the identified edges or identified nodescorresponding to at least one of the n-grams; determining a first scorefor each n-gram that corresponds to one of the identified edges oridentified nodes; selecting one or more of the identified edges and oneor more of the identified nodes based on their determined first scores,each of the one or more selected edges or selected nodes correspondingto at least one of the n-grams; generating one or more structuredqueries, each structured query corresponding to a grammar of acontext-free grammar model having one or more query tokens correspondingeach of the selected edges and nodes, wherein each structured querycomprises a natural-language string generated by the correspondinggrammar of the grammar model and further comprising the query tokens ofthe corresponding grammar of the grammar model; and sending, to theclient system of the first user, one or more of the structured queriesfor display to the first user.
 2. The method of claim 1, furthercomprising accessing the context-free grammar model, wherein thecontext-free grammar model comprises a plurality of grammars, eachgrammar comprising one or more query tokens.
 3. The method of claim 2,further comprising identifying one or more grammars, each identifiedgrammar having one or more query tokens corresponding to at least one ofthe selected nodes and at least one of the selected edges.
 4. The methodof claim 3, further comprising determining a grammar-score for eachidentified grammar.
 5. The method of claim 4, wherein each structuredquery corresponds to an identified grammar having grammar-score greaterthan a threshold grammar-score.
 6. The method of claim 4, whereindetermining the grammar-score for each identified grammar is based on adegree of separation between a first node of the social graphcorresponding to the first user and one or more second nodes of thesocial graph corresponding to one or more query tokens of the grammar,respectively.
 7. The method of claim 4, wherein determining thegrammar-score for each identified grammar is based on the selected edgescorresponding to the query tokens of the grammar.
 8. The method of claim4, wherein determining the grammar-score for each identified grammar isbased on the number of selected edges connected to the selected nodescorresponding to the query tokens of the grammar.
 9. The method of claim4, wherein determining the grammar-score for each identified grammar isbased on a search history associated with the first user.
 10. The methodof claim 1, wherein, for each structured query, one or more of the querytokens of the structured query corresponds to at least one of theidentified nodes and at least one of the identified edges of the socialgraph.
 11. The method of claim 1, further comprising accessing thesocial graph, wherein each of the edges between two of the nodesrepresents a single degree of separation between them, the nodescomprising: a first node corresponding to the first user; and aplurality of second nodes that each correspond to a concept or a seconduser associated with the online social network.
 12. The method of claim1, wherein selecting one or more of the identified edges and one or moreof the identified nodes based on their determined first scorescomprises: selecting one or more edges having a determined first scoregreater than an edge-threshold score, each of the selected edgescorresponding to at least one of the n-grams; and selecting one or morenodes having a determined first score greater than a node-thresholdscore, each of the selected nodes being connected to at least one of theselected edges, each of the selected nodes corresponding to at least oneof the n-grams.
 13. The method of claim 1, wherein the one or more ofthe structured queries are sent in response to the unstructured textquery inputted by the first user.
 14. The method of claim 1, whereineach n-gram comprises one or more characters of text entered by thefirst user.
 15. The method of claim 1, wherein each n-gram comprises acontiguous sequence of n items from the text query.
 16. The method ofclaim 1, wherein the determined first score for each n-gram is aprobability that the n-gram corresponds to a particular identified edgeor a particular identified node.
 17. One or more computer-readablenon-transitory storage media embodying software that is operable whenexecuted to: receive, from a client device of a first user, anunstructured text query inputted by the first user, wherein theunstructured text query comprises one or more n-grams, the online socialnetwork being associated with a social graph comprising a plurality ofnodes and a plurality of edges connecting the nodes; identify, based onthe unstructured text query, one or more edges and one or more nodes ofthe social graph, each of the identified edges or identified nodescorresponding to at least one of the n-grams; determine a score for eachn-gram that corresponds to one of the identified edges or identifiednodes; select one or more of the identified edges and one or more of theidentified nodes based on their determined scores, each of the one ormore selected edges or selected nodes corresponding to at least one ofthe n-grams; generate one or more structured queries, each structuredquery corresponding to a grammar of a context-free grammar model havingone or more query tokens corresponding each of the selected edges andnodes, wherein each structured query comprises a natural-language stringgenerated by the corresponding grammar of the grammar model and furthercomprising the query tokens of the corresponding grammar of the grammarmodel; and send, to the client system of the first user, one or more ofthe structured queries for display to the first user.
 18. A systemcomprising: one or more processors; and a memory coupled to theprocessors comprising instructions executable by the processors, theprocessors operable when executing the instructions to: receive, from aclient device of a first user, an unstructured text query inputted bythe first user, wherein the unstructured text query comprises one ormore n-grams, the online social network being associated with a socialgraph comprising a plurality of nodes and a plurality of edgesconnecting the nodes; identify, based on the unstructured text query,one or more edges and one or more nodes of the social graph, each of theidentified edges or identified nodes corresponding to at least one ofthe n-grams; determine a score for each n-gram that corresponds to oneof the identified edges or identified nodes; select one or more of theidentified edges and one or more of the identified nodes based on theirdetermined scores, each of the one or more selected edges or selectednodes corresponding to at least one of the n-grams; generate one or morestructured queries, each structured query corresponding to a grammar ofa context-free grammar model having one or more query tokenscorresponding each of the selected edges and nodes, wherein eachstructured query comprises a natural-language string generated by thecorresponding grammar of the grammar model and further comprising thequery tokens of the corresponding grammar of the grammar model; andsend, to the client system of the first user, one or more of thestructured queries for display to the first user.